/*
 * @(#)xin.tianhui.cloud.weblog.core.thymeleaf.processor.attribute
 * @(#)DemoAttrProcessor.java	2018-04-05
 * 
 * Copyright © 2018-2027, All rights reserved.
 * homeanter
 */
package xin.tianhui.cloud.weblog.thymeleaf.processor;


import org.thymeleaf.context.ITemplateContext;
import org.thymeleaf.engine.AttributeName;
import org.thymeleaf.model.IProcessableElementTag;
import org.thymeleaf.processor.element.IElementTagStructureHandler;
import org.thymeleaf.standard.processor.AbstractStandardExpressionAttributeTagProcessor;
import org.thymeleaf.templatemode.TemplateMode;


import lombok.extern.slf4j.Slf4j;

/**
 * 文章方言
 * @author junchen homeanter@163.com
 * @Data 2018-04-09 16:05:02
 */
@Slf4j
public class DemoAttrProcessor extends AbstractStandardExpressionAttributeTagProcessor {

	private static final String ATTRIBUTE_NAME = "demo";
	private static final int PRECEDENCE = 300;

	public DemoAttrProcessor(String dialectPrefix) {
		super(
				// 该处理器只适用于HTML模式
				TemplateMode.HTML,
				// 前缀用于名称匹配
				dialectPrefix,
				// 属性,将匹配的名称
				ATTRIBUTE_NAME,
				// 优先级(方言内部的优先)
				PRECEDENCE,
				// 删除匹配的属性
				true);
	}

	@Override
	protected void doProcess(ITemplateContext context, IProcessableElementTag tag, AttributeName attributeName,
			String attributeValue, Object expressionResult, IElementTagStructureHandler structureHandler) {
		structureHandler.setLocalVariable("test", 1);
		log.debug("{}",expressionResult);
	}

}
